import 'package:word_game/engine/core.dart';
import 'auto_fillin_event.dart';

class Altar extends Scene with Embeddable {
  Altar(Map map) : super({...map,'name': '祭坛'}) {
    add(AutoFillinEvent());
  }

  List<String> thingCode = [
    'essence_of_water',
    'essence_of_earth',
    'essence_of_gold',
    'essence_of_fire',
    'essence_of_wood',
  ];

  @override
  int get holeCount => 5;

  @override
  void fillin() {
    for (var item in World.instance.hero.bag.things.reversed.toList()) {
      if (thingCode.contains(item.code)) {
        bool hasFillin = false;
        for (var thing in holes) {
          if (thing.code==item.code) {
            hasFillin = true;
            break;
          }
        }
        if (!hasFillin) {
          holes.add(item);
          World.instance.hero.pureRemoveThing(item);
          Engine.instance.displayer.displayString('你把[${item.name}]嵌入了[${name}]。');
        }
      }
    }
    if (holes.length==holeCount) {
      holes.clear();
      Engine.instance.displayer.displayString('祭坛被激活了。');
      World.instance.hero.attackPower += 30;
      World.instance.hero.maxVitality += 300;
      World.instance.hero.vitality = World.instance.hero.maxVitality;
    }
  }

  @override
  String optionCommandsDesc() {
    String result = '${name}有${holeCount}个可镶嵌的位置，内容分别是：';
    for (int i=0;i<holeCount;i++) {
      if (i<holes.length) {
        var item = holes[i];
        result += '[${item.name}]';
      } else {
        result += '[]';
      }
    }
    return result + '\n' + super.optionCommandsDesc();
  }
}